//
//  ChannelNum.m
//  DianNaoWang
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ForITPageSearchCell.h"
#import "Header.h"
@implementation ForITPageSearchCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatViews];
    }
    return self;
}

- (void)creatViews
{
    
    _title = [[UILabel alloc]init ];
    _title.numberOfLines = 0;
    
    _title.font = contentTextSize;
    _title.backgroundColor = [UIColor redColor];
    
    [self.contentView addSubview:_title];
    
    _date = [[UILabel alloc]init];
    _date.numberOfLines = 0;
    
    _date.font = otherTextSize;
    
    [self.contentView addSubview:_date];
    
    _comment_numa = [[UILabel alloc]init];
    _comment_numa.numberOfLines = 0;
    
    _comment_numa.font = otherTextSize;
    
    [self.contentView addSubview:_comment_numa];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    _title.textColor = contenttextColor;
    _title.backgroundColor = BackgroundColor;
    _date.textColor = otherTextColor;
    _date.backgroundColor = BackgroundColor;
    _comment_numa.textColor = otherTextColor;
    _comment_numa.backgroundColor = BackgroundColor;
#pragma mark 关键字高亮
    if (_keyWork && _FITPModel.title) {
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:_FITPModel.title];
        ////NSLog(@"%@----%@", _FITPModel.title, _keyWork);
        NSRange range = [_FITPModel.title rangeOfString:_keyWork];
        [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:15], NSFontAttributeName, nil] range:range];
        _title.attributedText = attributedString;
    }
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:contentTextSize, NSFontAttributeName, nil];
    CGRect rect = [_title.text boundingRectWithSize:CGSizeMake(ScreenWidth - 20 * FitWidth, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    _title.frame = CGRectMake(10 * FitWidth, 10 * FitHeight, ScreenWidth - 20 * FitWidth, rect.size.height);
    _date.frame = CGRectMake(_title.frame.origin.x, _title.frame.origin.y + _title.frame.size.height + 10 * FitHeight, 150 * FitWidth, 20 * FitHeight);
    _comment_numa.frame = CGRectMake(ScreenWidth - 50 * FitWidth, _date.frame.origin.y, 40 * FitWidth, 20 * FitHeight);
    
}


-(void)setFITPModel:(ForITPageSearchModel *)FITPModel
{
    if (_FITPModel != FITPModel) {
        _FITPModel = FITPModel;
        _keyWork = nil;
    }
    _title.text = FITPModel.title;
    _date.text = FITPModel.date;
    _comment_numa.text = [NSString stringWithFormat:@"%ld 评论", FITPModel.comment_num];
}

//-(void)setKeyWork:(NSString *)keyWork
//{
//    if (_FITPModel.title) {
//        //pragma mark 关键字高亮
//        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:_FITPModel.title];
//        //NSLog(@"%@----%@", _FITPModel.title, keyWork);
//        NSRange range = [_FITPModel.title rangeOfString:keyWork];
//        [attributedString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:15], NSFontAttributeName, nil] range:range];
//        _title.attributedText = attributedString;
//    }
//}











/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
